package com.blues.framework.db.handlers;

import org.apache.commons.dbutils.handlers.*;
import java.sql.ResultSet;
import java.sql.SQLException;
import org.apache.commons.dbutils.ResultSetHandler;

/**
 * 简单类型取值
 * @author Rookie.Zhang	2006-12-31 10:23:36.
 */
public class AtomTypeScalarHandler
    implements ResultSetHandler {

    public AtomTypeScalarHandler() {
        columnIndex = 1;
        columnName = null;
    }

    public AtomTypeScalarHandler(int columnIndex) {
        columnName = null;
        this.columnIndex = columnIndex;
    }

    public AtomTypeScalarHandler(String columnName) {
        columnIndex = 1;
        this.columnName = columnName;
    }

    public Object handle(ResultSet rs)
        throws SQLException {
        if(rs.next())
        {
            if(columnName == null)
                return rs.getString(columnIndex);
            else
                return rs.getString(columnName);
        } else
        {
            return null;
        }
    }

    private int columnIndex;
    private String columnName;
}
